<%@page import="net.sf.json.JSON"%>
<%@page import="net.sf.json.JSONArray"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@include file="common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String deviceId= request.getParameter("deviceId");
%>

<!DOCTYPE>
<html style="font-size: 100px;">
  <head>
    <title>智慧消防</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<script type="text/javascript" src="<%=request.getContextPath()%>/js/city.js"></script>
  	<script type="text/javascript" src="<%=request.getContextPath()%>/js/qqmap.js"></script>
	  <link rel="stylesheet" href="<%=request.getContextPath()%>/css/common.css" type="text/css"></link>
	  <link href="<%=request.getContextPath()%>/css/bootstrap.min.css" rel="stylesheet">
	  <!-- 调用百度api -->
	  <script type="text/javascript" src="<%=request.getScheme()%>://api.map.baidu.com/api?v=2.0&ak=dwbzRtGa41pgkcduhiEZGjXpxmFtmGcf"></script>
	  <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
	  <script type="text/javascript">
    	var userArr;
    	/* 百度地图定位-开始 */
	    $(function(){
            getLocation(true);
            getProvince();
 		    getPerson();
 		    /* 选择用户获得联系方式 -开始*/
 		    $('#userId1').change(function(){
    			var index = $(this).get(0).selectedIndex;
    			var phone = userArr[index].phone;
    			$("#phone1").val(phone);
    		});
    		$('#userId2').change(function(){
    			var index = $(this).get(0).selectedIndex;
    			var phone = userArr[index].phone;
    			$("#phone2").val(phone);
    		});
    		/* 选择用户获得联系方式-结束 */
	    });

        /* 获取用户信息 */
		function getPerson(){
  			var url = '${linkPath}smartfire/wx/sysUser/getList';
  			   $.ajax({
		        url:url,
		        type: 'get',
		        data: {'orgId': orgId},
                   beforeSend: function(request) {
                       request.setRequestHeader("ACCESS-TOKEN", token);
                   },
		        success: function(res){
		            userArr = res.obj;
		            var user1 = $("#userId1");
		            var user2 = $("#userId2");
                    if (userArr != null && userArr.length > 0) {
                        for (var i = 0; i < userArr.length; i++) {
                            user1.append('<option value="' + userArr[i].id + '">' + userArr[i].truename + '</option>');
                            user2.append('<option value="' + userArr[i].id + '">' + userArr[i].truename + '</option>');
                        }
                    }
		        },
		        error: function(error){
		            console.log(error)
		        }
		    });
  		}

  		function saveDeviceInfo(){
  			var deviceId = $.trim($('#deviceId').val());
  			var lat = $.trim($('#lat').val());
  			var lng = $.trim($('#lng').val());
  			var address = $.trim($('#address').val());
            if($.trim(address)==""){
                $('span.address').html("详细地址不能为空");
                return false;
            }
  			var deviceName = $('#deviceName').val();
  			if($.trim(deviceName)==""){
  				$('#deviceName').focus();
                $('span.deviceName').html("设备名称不能为空");
  				return false;
  			}
            var deviceImg = $('#attachment').html();
  			var protectAreaId = $('#protectAreaId').val();
            if($.trim(protectAreaId)==""){
                $('span.protectAreaId').html("请选择保护区域");
                return false;
            }
  			var deviceType = $('#deviceType').val();
  			var userId1 = $.trim($('#userId1').val());
            if($.trim(userId1)==""){
                $('span.userId1').html("请选择负责人1");
                return false;
            }
  			var userId2 = $.trim($('#userId2').val());
            if($.trim(userId2)==""){
                $('span.userId2').html("请选择负责人2");
                return false;
            }

  			var url = '${linkPath}smartfire/wx/windpower/save';
            $.ajax({
                url:url,
                type: 'post',
                data: JSON.stringify({
					'deviceId': deviceId,
                    'lat': lat,
                    'lng': lng,
                    'address': address,
                    'deviceName': deviceName,
					'deviceImg':deviceImg,
                    'protectAreaId': protectAreaId,
                    'deviceType' : deviceType,
                    'responsiblePerson1' : userId1,
                    'responsiblePerson2' : userId2}),
                beforeSend: function(request) {
                    request.setRequestHeader("ACCESS-TOKEN", token);
                },
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function(res){
                    if(res.success){
                        myAlert("添加成功");
                        setTimeout(function(){
                            location.href ='<%=path %>/login/main.jsp';
                        },1000);
                    }else{
                        myAlert(res.msg);
                    }
                },
                error: function(error){
                    console.log(error);
                }
            });

  		}


    </script>
  </head>
  
  <body>
  <div class="bar">
	  <div class="naviBar">
		  <img onclick="javascript:history.back(-1);" src="<%=path %>/images/common/return.png" alt="">
		  <span>风电设备</span>
	  </div>

	  <div class="col-sm-6" style="margin-top: 0.40rem;padding-bottom: 0.4rem">
		  <div class="ibox float-e-margins" style="padding-top: 10px;">
			  <div class="ibox-content" style="display: block;">
				  <%-- <form class="form-horizontal m-t" id="signupForm" novalidate="novalidate">--%>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">设备ID：</label>
					  <div class="col-sm-8">
						  <input id="deviceId" name="deviceId" class="form-control" type="text" value ="<%=deviceId %>" readonly>
						  <span class="help-block m-b-none deviceId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">经度：</label>
					  <div class="col-sm-8">
						  <input id="lng" name="lng" class="form-control" type="text" placeholder="经度">
						  <span class="help-block m-b-none lng"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">纬度：</label>
					  <div class="col-sm-8">
						  <input id="lat" name="lat" class="form-control" type="text" placeholder="纬度">
						  <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">详细地址：</label>
					  <div class="col-sm-8">
						  <input id="address" name="address" class="form-control" type="text" placeholder="详细地址">
						  <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">设备名称：</label>
					  <div class="col-sm-8">
						  <input id="deviceName" name="deviceName" class="form-control" type="text">
						  <span class="help-block m-b-none deviceName"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">设备类型</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" name="deviceType" id="deviceType">
							  <option value="1" selected="selected">NB终端型</option>
						  </select>
						  <span class="help-block m-b-none deviceType"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">图片：</label>
					  <div class="col-sm-8">
						  <form id= "uploadForm" style="margin-bottom: 0">
							  <div class="input-group">
								  <label for="imgFile" class="input-group-addon" onclick="checkImg()" >选择图片</label>
								  <input type="file" id="file" name="file" style="display: none;">
								  <input type="text" class="form-control file" placeholder="图片路径">
								  <div id="attachment" style="display: none;"></div>
							  </div>
						  </form>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">省</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" name="province" id="province" onchange="getCity()">
							  <option value="">---省---</option>
						  </select>
						  <select class="form-control m-b pro" style="margin: 5px 0px" name="city" id="city" onchange="getArea()">
							  <option value="">---市---</option>
						  </select>
						  <select class="form-control m-b pro city" name="area" id="area" onchange="getVillage()">
							  <option value="">---区---</option>
						  </select>
						  <span class="help-block m-b-none province"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label ">行政村</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b pro city area" name="villageId" id="villageId"  onchange="getProtectAreaGroup('05')">
							  <option value="">---风电站场---</option>
						  </select>
						  <span class="help-block m-b-none villageId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">保护区域组</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b pro city area village" name="protectAreaGroupId" id="protectAreaGroupId" onchange="getProtectArea('05')">
							  <option value="">---保护区域组---</option>
						  </select>
						  <span class="help-block m-b-none protectAreaGroupId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">保护区域</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b pro city area village group" name="protectAreaId" id="protectAreaId">
							  <option value="">---保护区域---</option>
						  </select>
						  <span class="help-block m-b-none protectAreaId"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">负责人1</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" name="userId1" id="userId1">
							  <option value="">---负责人1---</option>
						  </select>
						  <span class="help-block m-b-none userId1"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">电话：</label>
					  <div class="col-sm-8">
						  <input id="phone1" name="phone1" class="form-control" aria-required="true" aria-invalid="false" type="text">
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-2 control-label">负责人2</label>
					  <div class="col-sm-10">
						  <select class="form-control m-b" name="userId2" id="userId2">
							  <option value="">---负责人2---</option>
						  </select>
						  <span class="help-block m-b-none userId2"><i class="fa fa-info-circle"></i> </span>
					  </div>
				  </div>
				  <div class="form-group">
					  <label class="col-sm-3 control-label">电话：</label>
					  <div class="col-sm-8">
						  <input id="phone2" name="phone2" class="form-control" aria-required="true" aria-invalid="false" type="text">
					  </div>
				  </div>

				  <div class="form-group" style="padding-top: 10px">
					  <div class="col-sm-8 col-sm-offset-3">
						  <button class="btn btn-primary" style="width: 100%"  onclick="saveDeviceInfo()">提交</button>
					  </div>
				  </div>
				  <%-- </form>--%>
			  </div>
		  </div>
	  </div>
  </div>
  </body>
  <script type="text/javascript" src="<%=request.getContextPath()%>/js/uploadOneImg.js"></script>
</html>
